package io.hx.modules.hos.controller;

import java.util.Arrays;
import java.util.Map;

import io.hx.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.hx.modules.hos.entity.OutpatientEntity;
import io.hx.modules.hos.service.OutpatientService;
import io.hx.common.utils.PageUtils;
import io.hx.common.utils.R;



/**
 * 科室表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2023-03-21 11:36:40
 */
@RestController
@RequestMapping("hos/outpatient")
public class OutpatientController {
    @Autowired
    private OutpatientService outpatientService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("hos:outpatient:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = outpatientService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("hos:outpatient:info")
    public R info(@PathVariable("id") Integer id){
        OutpatientEntity outpatient = outpatientService.getById(id);

        return R.ok().put("outpatient", outpatient);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("hos:outpatient:save")
    public R save(@RequestBody OutpatientEntity outpatient){
        outpatientService.save(outpatient);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("hos:outpatient:update")
    public R update(@RequestBody OutpatientEntity outpatient){
        ValidatorUtils.validateEntity(outpatient);
        outpatientService.updateById(outpatient);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("hos:outpatient:delete")
    public R delete(@RequestBody Integer[] ids){
        outpatientService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
